
#import "SMListCardCell.h"
#import <Masonry/Masonry.h>
#import <SDWebImage/UIImageView+WebCache.h>
@implementation SMListCardCell {
    UIView *_card;
    UIImageView *_thumb;
    UILabel *_titleL;
    UILabel *_subL;
    UILabel *_metaL;
    UIView *_line;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)rid {
    if (self=[super initWithStyle:style reuseIdentifier:rid]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = UIColor.systemGroupedBackgroundColor;
        _card=[UIView new];
        _card.backgroundColor = UIColor.secondarySystemBackgroundColor;
        _card.layer.cornerRadius=12; _card.layer.masksToBounds=YES;
        [self.contentView addSubview:_card];
        [_card mas_makeConstraints:^(MASConstraintMaker *make){
            make.edges.equalTo(self.contentView).insets(UIEdgeInsetsMake(8, 12, 8, 12));
            make.height.mas_greaterThanOrEqualTo(88);
        }];
        _thumb=[UIImageView new]; _thumb.contentMode=UIViewContentModeScaleAspectFill; _thumb.clipsToBounds=YES; _thumb.layer.cornerRadius=8;
        [_card addSubview:_thumb];
        _titleL=[UILabel new]; _titleL.font=[UIFont systemFontOfSize:16 weight:UIFontWeightSemibold];
        _subL=[UILabel new]; _subL.font=[UIFont systemFontOfSize:13]; _subL.textColor=UIColor.secondaryLabelColor; _subL.numberOfLines=2;
        _metaL=[UILabel new]; _metaL.font=[UIFont systemFontOfSize:12]; _metaL.textColor=UIColor.tertiaryLabelColor;
        [_card addSubview:_titleL]; [_card addSubview:_subL]; [_card addSubview:_metaL];
        [_thumb mas_makeConstraints:^(MASConstraintMaker *make){ make.left.top.equalTo(self->_card).offset(12); make.bottom.equalTo(self->_card).offset(-12); make.width.mas_equalTo(100);}];
        [_titleL mas_makeConstraints:^(MASConstraintMaker *make){ make.top.equalTo(self->_card).offset(12); make.left.equalTo(self->_thumb.mas_right).offset(12); make.right.equalTo(self->_card).offset(-12);}];
        [_subL mas_makeConstraints:^(MASConstraintMaker *make){ make.top.equalTo(self->_titleL.mas_bottom).offset(6); make.left.right.equalTo(self->_titleL);}];
        [_metaL mas_makeConstraints:^(MASConstraintMaker *make){ make.left.right.equalTo(self->_titleL); make.bottom.equalTo(self->_card).offset(-10);}];
        _line=[UIView new];
        _line.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.3];
        [self.contentView addSubview:_line];
        [_line mas_makeConstraints:^(MASConstraintMaker *make){ make.left.equalTo(self.contentView).offset(12); make.right.equalTo(self.contentView).offset(-12); make.bottom.equalTo(self.contentView); make.height.mas_equalTo(0.5);}];
    }
    return self;
}
- (void)prepareForReuse { [super prepareForReuse]; [_thumb sd_cancelCurrentImageLoad]; _thumb.image=nil; }
- (void)configureWithImageURL:(NSString *)url title:(NSString *)title subtitle:(NSString *)subtitle meta:(NSString *)meta {
    UIImage *ph=nil; if (@available(iOS 13.0,*)) ph=[UIImage systemImageNamed:@"photo"];
    [_thumb sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:ph];
    _titleL.text = title ?: @"";
    _subL.text   = subtitle ?: @"";
    _metaL.text  = meta ?: @"";
}
@end
